{extend name="platform/base" /}

{block name="main"}
<style type="text/css">
	.brand_img img{
		width: 40px;
		height: 40px;
	}
</style>
<div class="row padder-v">
	<div class="col-sm-9">
		<a href="{:__URL('PLATFORM_MAIN/Goods/addGoodsBrand')}"
			class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加品牌 </a>
	</div>
	<div class="col-sm-2">
		<input type="text" class="input-sm form-control" id="search_text"
			placeholder="请输入品牌名称">
	</div>
	<div class="col-sm-1">
		<button class="btn btn-sm btn-default" type="button"
			onclick="LoadingInfo(1)">搜索</button>
	</div>
</div>
<section class="panel panel-default">
	<div class="table-responsive">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col width="3%">
				<col width="20%">
				<col width="20%">
				<col width="15%">
				<col width="20%">
				<col width="25%">
			</colgroup>
			<thead>
				<tr>
					<th class="center"><input type="checkbox"></th>
					<th class="center">图片</th>
					<th class="left">品牌名称</th>
					<th class="left">品牌首字母</th>
					<th class="left">品牌分类</th>
<!-- 					<th class="center">是否推荐</th> -->
					<th class="center">操作</th>
				</tr>
			</thead>
			<tbody id="list">
				<tr></tr>
			</tbody>
		</table>
	</div>
	{include file="platform/page" /}
</section>
{/block} {block name="script"}
<script type="text/javascript">	
$(function(){
	LoadingInfo(1);
});
	//加载数据
	function LoadingInfo(pageIndex) {
		var search_text = $("#search_text").val();
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/goods/goodsbrandlist')}",
			async : true,
			data : {
				"pageIndex" : pageIndex, "search_text" : search_text
			},
			success : function(data) {
				var html = '';
				$("#total_count_num").text(data["total_count"]);
				$("#page_count_num").text(data["page_count"]);
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						html += '<tr align="center">';
						html += '<td class="center"><div class="cell"><label ><input name="sub" type="checkbox" value="'+ data["data"][i]["brand_id"] +'" ></label></div></td>';
						if(data["data"][i]["brand_pic"]==''){
							html += '<td class="tal"></td>';
						}else{
							html += '<td class="tal"><div class="brand_img"><img src="'+ __IMG(data["data"][i]["brand_pic"]) +'"></div></td>';
						}
						html += '<td class="tal left">' + data["data"][i]["brand_name"] + '</td>';
						html += '<td class="left">' + data["data"][i]["brand_initial"] + '</td>';
						html += '<td class="left">'+data["data"][i]['category_id_1_name']+'&nbsp;'+data["data"][i]['category_id_2_name']+'&nbsp;'+data["data"][i]['category_id_3_name']+'</td>';
						html += '<td class="center"><a href="'+__URL('PLATFORM_MAIN/Goods/updateGoodsBrand?brand_id=' + data["data"][i]["brand_id"]) + '">修改</a>&nbsp;&nbsp;&nbsp;  <a href="javascript:void(0);" onclick="delBrand(' + data["data"][i]["brand_id"] + ')">删除</a></td> ';
						html += '</tr>';
					}
				} else {
					html += '<tr align="center"><td colspan="6">暂无品牌数据记录</td></tr>';
				}
				$("#list").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
			}
		});
	}
	/* 删除品牌 */
	function delBrand(brand_id) {
		$( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $(this).dialog('close');
					$.ajax({
						type : "post",
						url : "{:__URL('PLATFORM_MAIN/goods/deletegoodsbrand')}",
						data : {
							'brand_id' : brand_id
						},
						async : true,
						success : function(data) {
							if (data['code'] > 0) {
								showMessage('success', data["message"],'{:__URL("PLATFORM_MAIN/goods/goodsbrandlist")}');
							}else{
								showMessage('error', data["message"]);
							}
						}
					});
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                }
            },
            contentText:"你确定删除吗？",
            title:"消息提醒"
        });
	}
</script>
{/block}
